//
//  ViewController.m
//  Demo
//
//  Created by MengLong Wu on 2016/11/23.
//  Copyright © 2016年 MengLong Wu. All rights reserved.
//

#import "ViewController.h"
#import "SecondVC.h"
#define S_Height [UIScreen mainScreen].bounds.size.height
#define S_Width [UIScreen mainScreen].bounds.size.width
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_leftTableView;
    NSInteger _selectRow;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    _selectRow = 0;
    
    _leftTableView = [[UITableView alloc]initWithFrame:CGRectMake(S_Width-70, 40, 50, S_Height-80) style:UITableViewStylePlain];
    
    _leftTableView.delegate = self;
    _leftTableView.dataSource = self;
    _leftTableView.rowHeight = (S_Height-80)/7;
    
    [self.view addSubview:_leftTableView];
    
    [_leftTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    for (int i = 0; i<7; i++) {
        SecondVC *svc = [[SecondVC alloc]init];
        [self addChildViewController:svc];
    }
    
    SecondVC *svc = [self.childViewControllers objectAtIndex:0];
    svc.index = _selectRow;
    
    [self.view addSubview:svc.view];
    
    [self.view bringSubviewToFront:_leftTableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = [NSString stringWithFormat:@"第%ld行",indexPath.row+1];
    cell.textLabel.numberOfLines = 0;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_selectRow == indexPath.row) {
        cell.backgroundColor = [UIColor redColor];
    }else{
        cell.backgroundColor = [UIColor orangeColor];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _selectRow = indexPath.row;
    [_leftTableView reloadData];
    
    SecondVC *svc = [self.childViewControllers objectAtIndex:indexPath.row];
    
    svc.index = indexPath.row * 20;
    
    [self.view addSubview:svc.view];
    
    [self.view bringSubviewToFront:_leftTableView];
    
    
}







@end
